import {DialogForm} from 'custom/index'
import {editSuggestionDetailList, addSuggestionDetailList,getSuggestionById} from '../api'
import WtfbeSelect from '../components/WtfbeSelect.vue'
import WtfbySelect from '../components/WtfbySelect.vue'
import TsclztSelect from '../components/TsclztSelect.vue'
import ZrrSelect from "@/views/menus/n-customer-complaint-handling-new/components/ZrrSelect.vue";
import WjztSelect from "@/views/menus/n-customer-complaint-handling-new/components/WjztSelect.vue";
import TskhmcSelect from "@/views/menus/n-customer-complaint-handling-new/components/TskhmcSelect.vue";
import TskhdpSelect from "@/views/menus/n-customer-complaint-handling-new/components/TskhdpSelect.vue";
import YwdjrSelect from "@/views/menus/n-customer-complaint-registration-new/components/YwdjrSelect.vue";
// 引入自定义组件
const editDialog = new DialogForm('DialogForm')
const addDetailDialog = new DialogForm('DialogForm')

editDialog
    .width('80%')
    .getApi(async (_, row) => {
        if (!row.isAdd) {
            const suggest_row = await getSuggestionById({complaintId: row.complaintId})
            console.log('row', row)
            return {
                complaintId: suggest_row.complaintId,
                djsj: suggest_row.djsj,
                tskhdjqm: suggest_row.tskhdjqm,
                tswtfssj: suggest_row.tswtfssj,
                zdclry: suggest_row.zdclry,
                gjc: suggest_row.gjc,
                wtms: suggest_row.wtms,
                complaintDetailId: row.complaintDetailId,
                tskhmc: row.tskhmc,
                tskhdp: row.tskhdp,
                tskhzzh: row.tskhzzh,
                tsclnr: row.tsclnr,
                tsjgpdVal: row.tsjgpdVal,
                wgwtfbyVal: row.wgwtfbyVal,
                wgwtfbeVal: row.wgwtfbeVal,
                tsclztVal: row.tsclztVal,
                zrrqyVal: row.zrrqyVal,
                zrr: row.zrr,
                clfsVal: row.clfsVal,
                wjztVal: row.wjztVal,
                jqsj: row.jqsj,
                pdsj: row.pdsj ?? undefined,
                wjsj: row.wjsj ?? undefined,
                zdclrye: row.zdclrye,
            };
        }
    })
    .postApi(editSuggestionDetailList)
    // 投诉信息
    .useGroup('投诉信息')
    .useItem('djsj').label('登记时间').span(6).setProp('disabled', true).end()
    .useItem('tskhdjqm').label('投诉客户对接群名').span(6).setProp('disabled', true).end()
    .useItem('tswtfssj').label('投诉问题发生时间').span(6).setProp('disabled', true).end()
    .useItem('zdclry').label('处理人').span(6).setProp('disabled', true).end()
    .useItem('gjc').label('关键词').span(24).setProp('disabled', true).end()
    .useItem2('wtms').label('问题描述').span(24).setProp('disabled', true).end()
    .upto('DialogForm')
    // 基础信息组
    // 第一行
    .useGroup('投诉信息明细')

    .useCustomItem(TskhmcSelect, 'tskhmc').label('投诉客户名称').span(8).end()
    .useCustomItem(TskhdpSelect, 'tskhdp').label('投诉客户店铺').span(8).end()
    .useItem('tskhzzh').label('投诉客户子账号').span(8).end()
    // 第二行
    .useItem2('tsclnr').label('投诉处理内容').span(24).end()
    // 第三行
    .useDictSelect('tsjgpdVal', 'tsjg').label('投诉结果判定').setProp('widthLabel', 'tsjgpdName').required().span(6).end()
    .useCustomItem(WtfbySelect, 'wgwtfbyVal',).label('违规问题分部一').required().span(6).end()
    .useCustomItem(WtfbeSelect, 'wgwtfbeVal').label('违规问题分部二').required().span(6).end()
    .useCustomItem(TsclztSelect, 'tsclztVal').label('投诉处理状态').span(6).end()
    // 第四行
    .useDictSelect('zrrqyVal', 'company').label('责任人区域').setProp('widthLabel', 'zrrqyName').span(6).end()
    .useCustomItem(ZrrSelect, 'zrr').label('责任人').span(6).end()
    .useDictSelect('clfsVal', 'clfs').label('处理方式').setProp('widthLabel', 'clfsName').span(6).end()
    .useCustomItem(WjztSelect, 'wjztVal').label('完结状态').required().span(6).end()
    // 第五行
    .useItem('jqsj').label('接起时间').setProp('disabled', true).span(6).end()
    .useItem('pdsj').label('判定时间').setProp('disabled', true).span(6).end()
    .useItem('wjsj').label('完结时间').setProp('disabled', true).span(6).end()
    .useCustomItem(YwdjrSelect, 'zdclrye').label('处理人').required().span(6).end()

addDetailDialog
    .width('80%')
    .getApi(async (_, row) => {
        if (!row.isAdd) {
            return row;
        } else {
            // 新增模式下也返回 complaintId
            const suggest_row = await getSuggestionById({complaintId: row.complaintId})
            return {
                complaintId: suggest_row.complaintId,
                djsj: suggest_row.djsj,
                tskhdjqm: suggest_row.tskhdjqm,
                tswtfssj: suggest_row.tswtfssj,
                zdclry: suggest_row.zdclry,
                gjc: suggest_row.gjc,
                wtms: suggest_row.wtms,
            };
        }
    })
    .postApi(addSuggestionDetailList)
    // 投诉明细
    .useGroup('投诉信息')
    .useItem('djsj').label('登记时间').span(6).setProp('disabled', true).end()
    .useItem('tskhdjqm').label('投诉客户对接群名').span(6).setProp('disabled', true).end()
    .useItem('tswtfssj').label('投诉问题发生时间').span(6).setProp('disabled', true).end()
    .useItem('zdclry').label('处理人').span(6).setProp('disabled', true).end()
    .useItem('gjc').label('关键词').span(24).setProp('disabled', true).end()
    .useItem2('wtms').label('问题描述').span(24).setProp('disabled', true).end()
    .upto('DialogForm')
    // 基础信息组
    // 第一行
    .useGroup('投诉信息明细')
    .useItem('complaintDetailId').label('').setProp('type', 'hidden').end()
    .useItem('complaintId').label('').setProp('type', 'hidden').end()
    .useCustomItem(TskhmcSelect, 'tskhmc').label('投诉客户名称').span(8).end()
    .useCustomItem(TskhdpSelect, 'tskhdp').label('投诉客户店铺').span(8).end()
    .useItem('tskhzzh').label('投诉客户子账号').span(8).end()
    //第二行
    .useItem2('tsclnr').label('投诉处理内容').span(24).end()
    //第三行
    .useDictSelect('tsjgpdVal', 'tsjg').label('投诉结果判定').setProp('widthLabel', 'tsjgpdName').span(6).end()
    .useCustomItem(WtfbySelect, 'wgwtfbyVal',).label('违规问题分部一').span(6).end()
    .useCustomItem(WtfbeSelect, 'wgwtfbeVal').label('违规问题分部二').span(6).end()
    .useCustomItem(TsclztSelect, 'tsclztVal').label('投诉处理状态').span(6).end()
    // 第四行
    .useDictSelect('zrrqy', 'company').label('责任人区域').setProp('widthLabel', 'zrrqyName').span(6).end()
    .useCustomItem(ZrrSelect, 'zrr').label('责任人').span(6).end()
    .useDictSelect('clfsVal', 'clfs').label('处理方式').setProp('widthLabel', 'clfsName').span(6).end()
    .useCustomItem(WjztSelect, 'wjztVal').label('完结状态').span(6).end()
    // 第五行
    .useItem('jqsj').label('接起时间').setProp('disabled', true).span(6).end()
    .useItem('pdsj').label('判定时间').setProp('disabled', true).span(6).end()
    .useItem('wjsj').label('完结时间').setProp('disabled', true).span(6).end()
    .useCustomItem(YwdjrSelect, 'zdclrye').label('处理人').span(6).end()

export {editDialog, addDetailDialog}